var currentPage = 1;
var directType = 1;
var status = 2;

//列表
loadMyEssay(status, directType);

function loadMyEssay(status, directType) {
	$(document).ready(function() {
		init(currentPage);
	});

	function init(pageNo) {
		$("#index_newzhibo").html("");
		$.ajax({
			url: urlcore + "/api/zbDirectSeeding/zbDirectSeedingList?directType=" + directType + "&status=" + status + "&size=" + 32 + "&current=" + pageNo,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					if(data.data != null) {
						$.each(data.data.list, function(i, n) {

							var headImg = n.user.headImg == null ? "http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/sqz.png" : n.user.headImg;
							headImg = isHasImg(headImg);
							var userName = n.user.userName == "" ? "暂无" : n.user.userName;
							var title = n.title == "" ? "暂无" : n.title;
							var packRate = n.packRate == "" ? "0" : n.packRate;

							var imgUrl = n.imgUrl == "" ? "images/img13.jpg" : n.imgUrl;
							imgUrl = isHasImg(imgUrl);
							var statusName = '';
							var zbStatus = '';
							if(status == 1 && directType == 1) {
								zbStatus = '预告';

								var thislist1 =
									'<div class="index_zhibo">' +
									'<div class="index_zhibo_ren">' +
									'<dl>' +
									'<dt>' +
									'<img src="' + headImg + '" />' +
									'</dt>' +
									'<dd>' + userName + '</dd>' +
									'</dl>' +
									'</div>' +
									<!--视频-- >
									'<div class="index_zhibo_new">' +
									'<a target="_blank" href="5.0.2zhibo_zhibo.html?id=' + n.id + '" style="background: url("' + imgUrl + '") no-repeat no-repeat center; background-size: cover;">' +
									<!--时间-- >
									'<div class="index_zhibo_time">' +
									'<div><em class="em1">' + zbStatus + '</em>' + new Date(n.startTime).pattern("MM月dd日 hh:mm") + '</div>' +
									'</div>' +
									<!--播放-- >
									'<div class="index_zhibo_play">' +
									'<img src="images/index_play.png" />' +
									'</div>' +
									<!--标题-- >
									'<div class="index_zhibo_wenzi">' +
									'<h5>' + title + '</h5>' +
									'<p>打' + packRate + '折</p>' +
									'</div>' +
									'</a>' +
									'</div>' +
									'</div>';
								$('#index_newzhibo').append(thislist1);

							} else if(status == 2 && directType == 1) {
								zbStatus = '时间';
								statusName = '直播中';

								var thislist =
									'<div class="index_zhibo">' +
									'<div class="index_zhibo_ren">' +
									'<dl>' +
									'<dt>' +
									'<img src="' + headImg + '" />' +
									'</dt>' +
									'<dd>' + userName + '</dd>' +
									'</dl>' +
									'</div>' +
									<!--视频-- >
									'<div class="index_zhibo_new">' +
									'<a target="_blank" href="5.0.2zhibo_zhibo.html?id=' + n.id + '&status=2" style="background: url(' + imgUrl + ') no-repeat no-repeat center; background-size: cover;">' +
									<!--时间-- >
									'<div class="index_zhibo_time">' +
									'<div><em class="em">' + zbStatus + '</em>' + new Date(n.startTime).pattern("MM月dd日 hh:mm") + '</div>' +
									'<span>' + statusName + '</span>' +
									'</div>' +
									<!--播放-- >
									'<div class="index_zhibo_play">' +
									'<img src="images/index_play.png" />' +
									'</div>' +
									<!--标题-- >
									'<div class="index_zhibo_wenzi">' +
									'<h5>' + title + '</h5>' +
									'<p>打' + packRate + '折</p>' +
									'</div>' +
									'</a>' +
									'</div>' +
									'</div>';
								$('#index_newzhibo').append(thislist);

							} else if(status == 3 && directType == 1) {
								zbStatus = '回放';

								var thislist3 =
									'<div class="index_zhibo">' +
									'<div class="index_zhibo_ren">' +
									'<dl>' +
									'<dt>' +
									'<img src="' + headImg + '" />' +
									'</dt>' +
									'<dd>' + userName + '</dd>' +
									'</dl>' +
									'</div>' +
									<!--视频-- >
									'<div class="index_zhibo_new">' +
									'<a target="_blank" href="5.0.2zhibo_zhibo.html?id=' + n.id + '&status=3" style="background: url(' + imgUrl + ') no-repeat no-repeat center; background-size: cover;">' +
									<!--时间-- >
									'<div class="index_zhibo_time">' +
									'<div><em class="em3">' + zbStatus + '</em>' + n.watchAmount + '次观看</div>' +
									'</div>' +
									<!--播放-- >
									'<div class="index_zhibo_play">' +
									'<img src="images/index_play.png" />' +
									'</div>' +
									<!--标题-- >
									'<div class="index_zhibo_wenzi">' +
									'<h5>' + n.title + '</h5>' +
									'<p>打' + n.packRate + '折</p>' +
									'</div>' +
									'</a>' +
									'</div>' +
									'</div>';
								$('#index_newzhibo').append(thislist3);

							}
							var directTypeName = '';
							if(directType == 2 && status == 2) {
								zbStatus = '私密';
								directTypeName = '直播中';

								var thislist4 =
									'<div class="index_zhibo js_simi">' +
									'<div class="index_zhibo_ren">' +
									'<dl class="userName1">' +
									'<dt>' +
									'<img src="' + headImg + '" />' +
									'</dt>' +
									'<dd class="userName2"><input type="hidden" class="id" value="' + n.id + '"/><input type="hidden" class="password" value="' + n.password + '"/><input type="hidden" class="userName" value="' + userName + '"/>' + userName + '</dd>' +
									'</dl>' +
									'</div>' +
									<!--视频-- >
									'<div class="index_zhibo_new">' +
									'<a href="#" class="simi" style="background: url(' + imgUrl + ') no-repeat no-repeat center; background-size: cover;">' +
									<!--时间-- >
									'<div class="index_zhibo_time">' +
									'<div><em class="em">' + zbStatus + '</em>' + new Date(n.startTime).pattern("MM月dd日 hh:mm") + '</div>' +
									'<span>' + directTypeName + '</span>' +
									'</div>' +
									<!--锁-- >
									'<div class="index_zhibo_play">' +
									'<img src="images/zhibo_lock.png" />' +
									'</div>' +
									<!--标题-- >
									'<div class="index_zhibo_wenzi">' +
									'<h5>' + n.title + '</h5>' +
									'<p>打' + n.packRate + '折</p>' +
									'</div>' +
									'</a>' +
									'</div>' +
									'</div>';
								$('#index_newzhibo').append(thislist4);
							}

						});

						$(function() {

							$('.simi').click(function() {
								$("#sizbma").html("");
								var id = $(this).parent('div[class*=index_zhibo_new]').prev('div[class*=index_zhibo_ren]').find('dl[class*=userName1]').find('dd[class*=userName2]').find('input[class*=id]').val();
								var name = $(this).parent('div[class*=index_zhibo_new]').prev('div[class*=index_zhibo_ren]').find('dl[class*=userName1]').find('dd[class*=userName2]').find('input[class*=userName]').val();
								var password = $(this).parent('div[class*=index_zhibo_new]').prev('div[class*=index_zhibo_ren]').find('dl[class*=userName1]').find('dd[class*=userName2]').find('input[class*=password]').val();
								//弹框
								var simi_bg =
									'<div class="public_simi_bg">' +
									'<div class="public_simi">' +
									'<span class="span123" style="margin: 0 0 0 277px;cursor:pointer;font-weight:bold;">x</span>' +
									'<h5>' + name + '</h5>' +
									'<p>您的等级不够，无法进入直播请输入房间号，申请进入</p>' +
									'<input type="text" class="password1"  placeholder="输入房间号密码" />' +
									'<input type="button" class="button" value="进入房间" />' +
									'</div>' +
									'</div>';
								$('#sizbma').append(simi_bg);
								//弹框js
								$('.js_simi').on('click', function() {
									$(".public_simi_bg").fadeIn();
								});
								$(".span123").on('click', function() {
									$(".public_simi_bg").fadeOut();
								})

								$('.button').click(function() {
									var password1 = $('.password1').val();

									if(password != password1) {
										layer.alert("密码不正确！");
									} else {
										window.location.href = "5.0.2zhibo_zhibo.html?id=" + id + "&status=" + 2;
									}
								});
							});

						});

						$("#pager").pager({
							pagenumber: pageNo,
							pagecount: data.data.pages,
							totalcount: data.data.total,
							buttonClickCallback: PageClick
						});

					}

				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					//alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}

				} else {
					if(data.msg != '空数据') {
						layer.alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				layer.alert("error");
			}
		});
	}
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}
}

//按状态，公开私密查询查询
function selectZbDirectSeeding(status, directType) {
	loadMyEssay(status, directType);
}